<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
   // 如果一个数恰好等于它的因数之和，则称该数为“完美数”。

  // 函数定义
  function isPerfect(num = 0){
    if(num == 0){
      return true;
    }
    var sum = 1;
    for(var i = 2; i < Math.sqrt(num); i++){
      if(num % i == 0){ 
        sum += i; 
        sum += num/i; 
      }
    }    
    return num == sum;
  }

  //主程序
  console.log(isPerfect(36));
  console.log(isPerfect(6));

</script>
</html>